﻿using CoffeeShop.DAO;
using CoffeeShop.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CoffeeShop.BIZ
{
    public class OfficeBiz
    {
        private OfficeDao _officeDao = new OfficeDao();

        /// <summary>
        /// Convert param to Office object
        /// </summary>
        /// <param name="officeName"></param>
        /// <param name="officeAddress"></param>
        /// <param name="officePhone"></param>
        /// <returns></returns>
        private Office GetOfficeObject(string officeName, string officeAddress, string officePhone)
        {
            Office office = new Office();
            office.Name = officeName;
            office.Address = officeAddress;
            office.PhoneNumber = officePhone;
            return office;
        }

        /// <summary>
        /// Get all offices in Database
        /// </summary>
        /// <returns>List of Office</returns>
        public List<Office> GetAllOffices()
        {
            return _officeDao.GetAllOffices();
        }

        /// <summary>
        /// Get all offices are activate
        /// </summary>
        /// <returns></returns>
        public List<Office> GetListActiveOffice()
        {
            return _officeDao.GetListActiveOffice();
        }

        /// <summary>
        /// Add new Office in to Database
        /// </summary>
        /// <param name="office">O</param>
        /// <returns>True: Successful - False: Fail</returns>
        public bool AddOffice(string officeName, string officeAddress, string officePhone)
        {
            Office office = new Office();
            office = GetOfficeObject(officeName, officeAddress, officePhone);
            return _officeDao.AddOffice(office);
        }

        /// <summary>
        /// Delete an office in to Database
        /// </summary>
        /// <param name="office">O</param>
        /// <returns>True: Successful - False: Fail</returns>
        public bool DeleteOffice(int officeId)
        {
            return _officeDao.DeleteOffice(officeId);
        }

        /// <summary>
        /// Update an office
        /// </summary>
        /// <param name="office"></param>
        /// <returns></returns>
        public bool UpdateOffice(int officeId, string officeName, string officeAddress, string officePhone)
        {
            Office office = new Office();
            office = GetOfficeObject(officeName, officeAddress, officePhone);
            office.ID = officeId;
            return _officeDao.UpdateOffice(office);
        }

        /// <summary>
        /// Get an Office by Office's name
        /// </summary>
        /// <param name="officeName">Name of Office</param>
        /// <returns>True: Is Existed - False: Not Exist</returns>
        public bool IsExistOffice(string officeName)
        {
            Office office = new Office();
            office = _officeDao.GetOfficeByName(officeName);
            if (office != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Get an Office by Office's ID
        /// </summary>
        /// <param name="officeName">Name of Office</param>
        /// <returns>An Office or null</returns>
        public Office GetOfficeById(int officeId)
        {
            return _officeDao.GetOfficeById(officeId);
        }

        /// <summary>
        /// Check is exist an office which has the same name
        /// </summary>
        /// <param name="officeId"></param>
        /// <returns></returns>
        public bool IsExistedWhenUpdate(int officeId, string officeName)
        {
            return _officeDao.IsExistedWhenUpdate(officeId, officeName);
        }
    }
}